package net.learn.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.learn.framework.common.page.PageResult;
import net.learn.framework.common.utils.Result;
import net.learn.system.query.SysPaperQuery;
import net.learn.system.query.SysPaperQuestionQuery;
import net.learn.system.service.SysPaperQuestionService;
import net.learn.system.service.SysPaperService;
import net.learn.system.vo.SysPaperQuestionVO;
import net.learn.system.vo.SysPaperVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 试卷管理
 */
@RestController
@RequestMapping("sys/paperquestion")
@Tag(name="试卷题库管理")
@AllArgsConstructor
public class SysPaperQuestionController {

    @Autowired
    private final SysPaperQuestionService sysPaperQuestionService;

    @GetMapping("getPaperQuestion")
    @Operation(summary = "分页获取试卷题库列表")
    public Result<PageResult<SysPaperQuestionVO>> getPaper(@Valid SysPaperQuestionQuery query){
        PageResult<SysPaperQuestionVO> page = sysPaperQuestionService.qryPaperQuestionListPage(query);

        return Result.ok(page);
    }
    @PostMapping("getPaperQuestionList")
    @Operation(summary = "获取试卷题库列表")
    public Result<List<SysPaperQuestionVO>> getPaperQuestionList(@RequestBody SysPaperQuestionQuery query){
        List<SysPaperQuestionVO> list = sysPaperQuestionService.qryPaperQuestionList();

        return Result.ok(list);
    }
    @PostMapping("/updatePaperQuestion")
    @Operation(summary = "修改试卷题库")
    public Result<String> updatePaperQuestion(@RequestBody @Valid SysPaperQuestionVO vo){
        sysPaperQuestionService.updatePaperQuestion(vo);

        return Result.ok();
    }
    @PostMapping("save")
    @Operation(summary = "新增试卷")
    public Result<String> addPaperQuestion(@RequestBody List<SysPaperQuestionVO> voList){
        for(SysPaperQuestionVO vo :voList){
            sysPaperQuestionService.addPaperQuestion(vo);
        }

        return Result.ok();
    }

    @DeleteMapping
    @Operation(summary = "删除试卷题库")
    public Result<String> deleteById(@RequestBody List<Long> idList){
        sysPaperQuestionService.delete(idList);
        return Result.ok();
    }
}

